*Heterogeneous Effect by percentiles of a continuous var

foreach var of local outcome {
matrix a = J(100, 4, .)

areg `var' T T`he' `he' ${covariates} i.date $condition, ab(strata) cluster(strata)

qui run "$path/scripts/gcuan.do"
gcuan `he' if n==1, n(100) gen(percentil)
forvalues i = 1/100 {
	qui summ `he' if percentil==`i', d
	local p`i' = r(max)
}
	

	matrix V = e(V)
	local var_b1 = V[1,1]
	local var_b2 = V[2,2]
	local cov_b1_b2 = V[1,2]
	forvalues i = 1/99 {

		local beta=_b[T]+_b[T`he']*(`p`i'')
		local se = sqrt(`var_b1'+`p`i''*`p`i''*`var_b2'+2*`p`i''*`cov_b1_b2')
		local lb = `beta' - 1.96 * `se'
		local ub = `beta' + 1.96 * `se'	
		
		matrix a[`i',1] = `i' , `beta', `lb', `ub' 
}

qui coefplot (matrix(a[,2]), mlcolor(black) mfcolor(gray) ci((a[,3] a[,4])) ciopts(lc(gray) m(point) recast(rconnected) lpattern(dash))), yline(0, lwidth(medium) lcolor(black%80)) ylabel(, nogrid) ///
 ytitle("ITT") xtitle("Percentiles of baseline `bl'") vert xlabel(1 25 50 75 99, valuelabel) m(dh) graphr(color(white)) bgcolor(white)
 graph export "$path/Auxiliary/results/`var'_`he'_ITT.png", as(png) replace
drop percentil
}

drop n